import {Injectable} from '@angular/core';
import {Level} from './interface';

@Injectable()
export class CascaderService {
    genLevels(type, options?: Level[]) {
        let levels: Level[];
        switch (type) {
            case 'cityArea':
                levels = [
                    new Level({
                        title: '市',
                        selectedIdx: 0,
                        reqInfo: {
                            path: '/cityManagement/cityByProvinceId',
                            params: {},
                            method: 'GET'
                        },
                        labelFrom: 'name',
                        valueFrom: 'id',
                        targetKey: 'cityId',
                        reqProp: 'id'
                    }),
                    new Level({
                        title: '区/县',
                        reqInfo: {
                            path: '/cityManagement/areasByCityId',
                            params: {},
                            method: 'GET'
                        },
                        labelFrom: 'name',
                        valueFrom: 'id',
                        reqProp: 'id',
                        targetKey: 'areaId'
                    })
                ];
                break;
            case 'areaCountry':
                levels = [
                    new Level({
                        title: '区/县',
                        reqInfo: {
                            path: '/cityManagement/allAreaByProvinceId',
                            params: {},
                            method: 'GET'
                        },
                        labelFrom: 'name',
                        valueFrom: 'id',
                        reqProp: 'id',
                        targetKey: 'areaId'
                    }),
                    new Level({
                        title: '乡',
                        reqInfo: {
                            path: '/cityManagement/countryPageList',
                            params: {},
                            method: 'GET'
                        },
                        labelFrom: 'name',
                        valueFrom: 'id',
                        reqProp: 'id',
                        targetKey: 'countryId'
                    })
                ];
                break;
            case 'cityAreaCountry':
                levels = [
                    new Level({
                        title: '市',
                        selectedIdx: 0,
                        reqInfo: {
                            path: '/cityManagement/cityByProvinceId',
                            params: {},
                            method: 'GET'
                        },
                        labelFrom: 'name',
                        valueFrom: 'id',
                        targetKey: 'cityId',
                        reqProp: 'id'
                    }),
                    new Level({
                        title: '区/县',
                        reqInfo: {
                            path: '/cityManagement/areasByCityId',
                            params: {},
                            method: 'GET'
                        },
                        labelFrom: 'name',
                        valueFrom: 'id',
                        reqProp: 'id',
                        targetKey: 'areaId'
                    }),
                    new Level({
                        title: '乡',
                        reqInfo: {
                            path: '/cityManagement/countryByAreaId',
                            params: {},
                            method: 'GET'
                        },
                        labelFrom: 'name',
                        valueFrom: 'id',
                        reqProp: 'id',
                        targetKey: 'countryId'
                    })
                ];
                break;
        }
        return levels;
    }
}
